home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / util / Mac F2C 1.3.sit / Mac F2C 1.3 / Mac F2C v1.3 Documentation.rsrc / TEXT_136.txt < prev    next >
Text File  |  1995-12-11  |  15KB  |  168 lines

  1. Using Mac F2C With CodeWarrior C/C++
  2.  
  3.  
  4. Before you can use the code produced by Mac F2C, you must set up and build all of the required support libraries.  There are also special rules that must be followed when using code produced by Mac F2C.  The process and rules are slightly different for each compiler.  The instructions in this chapter are for setting up Mac F2C for use with Metrowerks CodeWarrior C/C++.  Refer to other chapters for instructions on how to set things up for use with Symantec C/C++ or THINK C/C++.
  5.  
  6. Users upgrading from earlier versions need to re-install all libraries, project files, and supporting files.  All files, including library source code, have been updated in version 1.3.    
  7.  
  8. Please note that the source code and libraries provided are set up for use 
  9. with CodeWarrior IDE v1.3.1 as updated from the version released on the CW7 CD using the freely available updater.  
  10.  
  11. If you are still using CodeWarrior v1.2 from the CW6 CD (the one with separate applications to build 68K and PPC executables), you can find CW6 versions of all the project files and stationary files in the folder CW6 Project Files which is located in the CodeWarrior Support folder.  Simply replace all the project files and stationary files referred to in these instructions with the corresponding files of the same name from the CW6 Project Files folder.
  12.  
  13. If you have a newer version of CW, first check if there is a more recent version of Mac F2C.  If not,  convert all the CW project files contained in the Mac F2C package by simply opening and closing themwith the new version of CW (answer ‚ÄúOK‚Äù when asked if you want to update the project file).  The CW project files you must convert are located in the Test Project Δí and Mac F2C Libraries folders.  Then run the installer.  If this does not work (I obviously can‚Äôt guarantee it will), let me know.
  14.  
  15.  
  16. Setting Up Mac F2C Using the Installer
  17.  
  18. The easiest way to set up Mac F2C is to use the installer included with Mac F2C.  This installer will only work correctly if you have System 7.5 (or higher) and have CodeWarrior IDE v1.3 (from the CW7 CD).  If you do not meet both of these requirements, please follow the instructions for manual installation found in the following section.
  19.  
  20. The installer is stand-alone AppleScript application called Mac F2C Installer.  To run the installer, simply double click on it, and answer the dialogs it presents.  The installer will do the following:
  21.  
  22. ‚Ä¢ Create a folder called Mac F2C Support within CodeWarrior‚Äôs MacOS Support folder.
  23. ‚Ä¢ Build the appropriate Mac F2C libraries.
  24. ‚Ä¢ Move the built libraries to the Mac F2C Support folder.
  25. ‚Ä¢ Copy the other support files (found in the For 'Mac F2C Support' folder: F2Cmain.c, F2Cmain.cp, f2c.h, and F2C Cursors.rsrc) to the Mac F2C Support folder.
  26. ‚Ä¢ Copy the Mac F2C project stationary files to CodeWarrior‚Äôs (Project Stationery) folder.
  27. ‚Ä¢ Translate and build the appropriate versions of the test application.
  28.  
  29. When the installer is finished, you will find completed test applications in the Test Project Δí folder.  You should run these to verify correct operation of Mac F2C and its libraries.  After that, you are ready to go.  To compile translated FORTRAN code, simply open a new project in CodeWarrior, select the appropriate version of Mac F2C stationary, and add the translated files.
  30.  
  31. The remaining sections provide step-by-step instructions for installing Mac F2C manually (including how to install for earlier CodeWarrior versions), a more detailed description of how to test your Mac F2C installation, and additional information on using code generated by Mac F2C with CodeWarrior.
  32.  
  33.  
  34. Setting Up Mac F2C Manually
  35.  
  36. Set up is a two step process.  First you must build the libraries, and then you must move several files to their proper locations.
  37.  
  38. Step 1: Build all the libraries
  39.  
  40. The libraries of the Mac F2C distribution come without binaries, so you have to build them according to the following algorithm. There are two versions of each library project, one for the 68K compiler and one for the PowerPC compiler. They are named with the usual extensions, 68K.¬µ and PPC.¬µ. You can use both versions or just one if you like (in that case, skip the instructions for which ever version you don‚Äôt want).
  41.  
  42. If you are using CW6 vice CW7, replace all the project files and stationary files referred to in these instructions with the corresponding files of the same name found in the folder CW6 Project Files located in the CodeWarrior Support folder.
  43.  
  44. FOR the project files in the Mac F2C Libraries folder:
  45.     (1) libI77.68K.¬µ
  46.     (2) libF77.68K.¬µ
  47.     (3) libI77.PPC.¬µ
  48.     (4) libF77.PPC.¬µ
  49. REPEAT the following steps:
  50.     (a) Double-click on the project file.  
  51.     (b) In the CW Environment‚Äôs Project menu, 
  52.          select the Make command.  
  53. END REPEAT
  54.  
  55. Step 2:  Move things to the recommended locations
  56.  
  57. For easiest and smoothest operation, the support libraries and other support files should be installed where the CodeWarrior C compiler can find them easily.  I recommend you install Mac F2C libraries and support files as follows:
  58.  
  59. ‚Ä¢ Create a folder called Mac F2C Support inside the MacOS Support folder within the  folder that contains the CodeWarrior application.  All of the libraries and files required to support Mac F2C code will be placed in this folder. 
  60.  
  61. CW6 doesn‚Äôt have a MacOS Support folder, so simply create the Mac F2C Support folder  inside the Metrowerks  C/C++ Δí folder.
  62.  
  63. ‚Ä¢ Drag the libraries libI77.68K, libF77.68K, libI77.PPC, and libF77.PPC you obtained by following the instructions of Step 1 from the folder Mac F2C Libraries to the Mac F2C Support folder that you just created. 
  64.  
  65. WARNING:  Do not place the source code  for these libraries (found in the folders libF77 Sources and libI77 Sources) in the folder containing the CodeWarrior application or in any of it‚Äôs sub-folders).  The source code for these libraries has name conflicts with Apple‚Äôs Universal Headers (e.g., a file called fp.h appears in both but the two are not equivalent files).  Otherwise any of your code that #includes any of the conflicted files may inadvertently access the wrong file.
  66.     
  67. ‚Ä¢ The For '(Project Stationary)' located in the CodeWarrior Support folder contains project stationary files that are used for compiling C and C++ code produced by Mac F2C.  Drag the project stationary files to the (Project Stationary) folder found in the folder that contains the CodeWarrior application.
  68.  
  69. ‚Ä¢ The For 'Mac F2C Support' folder located in the CodeWarrior Support folder contains files (f2c.h, F2Cmain.c,  F2Cmain.cp, and F2Ccursors.rsrc) that are needed to compile C programs produced by Mac F2C.  Drag these files to to the Mac F2C Support folder you created earlier inside the MacOS Support folder.
  70.  
  71. CW6 doesn‚Äôt have a MacOS Support folder; for CW6 the Mac F2C Support folder was created inside the Metrowerks C/C++ Δí folder.
  72.  
  73.  
  74. Verifying Correct Operation of Mac F2C
  75.  
  76. The folder Test Project Δí contains the following files relevant to CodeWarrior:
  77.  
  78. test.f -- a sample FORTRAN program.
  79.  
  80. F2Cmain.c -- the main program required to run programs produced by  Mac F2C.
  81.  
  82. F2Cmain.cp -- the main program required to run programs produced by  Mac F2C.
  83.  
  84. f2c.h -- an include file required to compile programs produced by Mac F2C.
  85.  
  86. test.c (C Output) -- what you should get when you translate the sample FORTRAN code files.
  87.  
  88. Test.68K.¬µ and Test.PPC.¬µ -- CodeWarrior projects to run the sample program. These serve as models for how to compile, link, and run C code produced by Mac F2C. 
  89.  
  90. test.cp (C++ Output) -- what you should get when you translate 
  91. the sample FORTRAN code files and select the C++ output option.
  92.  
  93. Test++.68K.¬µ and Test++.PPC.¬µ -- CodeWarrior projects to run the sample program when Mac F2C is used to produce C++ output. These serve as models for how to compile, link, and run C++ code produced by Mac F2C. 
  94.     
  95. Translate the sample FORTRAN program Test.f simply by dragging it onto Mac F2C.  Do not change any of the options (use Factory Defaults).  Once you have done this you can compare it with Test.c (C Output) file to verify that you got the same thing.  If so, double click on the CodeWarrior project Test.68K.¬µ or Test.PPC.¬µ and run it to verify correct operation.
  96.  
  97. If you also plan to use Mac F2C C++ output with the Codewarrior, you can run a second test to verify correct operation with the C++ compiler.  Start Mac F2C and in the C Options dialog, select C++ code.  Do not change any of the other options.  Translate Test.f.  Compare it with Test.cp (C++ Output) to verify that you got the same thing.  If so, double click on the CodeWarrior project Test++.68K.¬µ or Test++.PPC.¬µ and run it to verify correct operation.
  98.  
  99.  
  100. Using C Code Generated by Mac F2C
  101.  
  102. The C code produced by Mac F2C has the following compile and link requirements:
  103.  
  104. 68K version:
  105.     ‚Ä¢ the header file:
  106.          f2c.h
  107.     ‚Ä¢ the F2C libraries: 
  108.                                     libI77.68K 
  109.                                     libF77.68K
  110.     ‚Ä¢ the CodeWarrior libraries: 
  111.        ANSIFa(4i/8d)C.68K.Lib
  112.        MathLib68K (4i/8d).Lib
  113.        SIOUX.68K.Lib
  114.        MacOS.lib    
  115.     ‚Ä¢ for C++ code only, the CodeWarrior libraries:
  116.        ANSIFa(4i/8d)C++.68K.Lib
  117.        CPlusPlus.Lib
  118.     ‚Ä¢ 4-byte integers
  119.     ‚Ä¢ 8-byte doubles
  120.     ‚Ä¢ Far Data
  121.     ‚Ä¢ Smart code model
  122.  
  123. PPC version:
  124.     ‚Ä¢ the header file:
  125.        f2c.h
  126.     ‚Ä¢ the F2C libraries: 
  127.        libI77.PPC 
  128.        libF77.PPC
  129.     ‚Ä¢ the CodeWarrior libraries:  
  130.        ANSI C.PPC.Lib
  131.        MWCRuntime.Lib 
  132.        Interface.Lib
  133.        SIOUX.PPC.Lib
  134.        MathLib 
  135.     ‚Ä¢ for C++ code only, the CodeWarrior library:
  136.        ANSI C++.PPC.Lib
  137.     
  138. In addition, if you compile a stand-alone FORTRAN program (instead of only some FORTRAN subroutines) you must include F2Cmain.c in your project (or F2Cmain.cp if you use C++; the two files are identical).  This is because the original main routine in the FORTRAN program becomes a function that is called by F2Cmain.c.  In addition, F2Cmain.c performs a series of initializations (primarily related to error catching) prior to executing the main FORTRAN program.
  139.  
  140. The For '(Project Stationary)' and For 'Proj Stationary Support' folders provided in the CodeWarrior Support folder contain everything you need to compile and run code produced by Mac F2C.  Copy the project stationary files from the For '(Project Stationary)' folder to the (Project Stationary) folder, and copy the files in the For 'Proj Stationary Support' folder to the 
  141. Project Stationary Support folder located inside the (Project Stationary). 
  142.  
  143. To start a new project using Mac F2C code, launch the CodeWarrior application, select New Project‚Ķ, and then choose the appropriate Mac F2C project stationary in the resulting Standard File dialog.  Then add your code files to the project and bring everything up-to-date.  Use the ‚ÄúC‚Äù versions of project stationary to work with C code generated by Mac F2C and the ‚ÄúC++‚Äù versions of project stationary to work with C++ code generated by Mac F2C.
  144.  
  145. If you compile a FORTRAN subroutine or function that you want to call from a C program, look at the output C code to see the appropriate calling protocol.  You may or may not need to include the F2C support libraries (libF77 and libI77).  In rare cases, you may also need to copy some of the initialization code from F2Cmain.c to your calling program.
  146.  
  147.  
  148. Special 68K Considerations
  149.  
  150. Please read the following section carefully if you intend to use Mac F2C with the CodeWarrior 68K compiler (the PPC compiler doesn‚Äôt give you any of the options mentioned, so there is nothing to consider):
  151.  
  152. As noted above, code produced by Mac F2C MUST be compiled with 4-byte integers.  This requirement cannot be relaxed.  The other requirements (8-byte doubles, far data) can sometimes be relaxed:
  153.  
  154. IF you do not use doubles in any situation where their size relative to reals matters (e.g., if you do not use doubles in equivalence and common statements), then your code probably does not require 8-byte doubles.  You need to verify this on a case-by-case basis.
  155.  
  156. This requirement exists because Mac F2C follows FORTRAN sizing rules when compiling FORTRAN code:  sizeof(real) == sizeof(integer) and sizeof(double) == 2*sizeof(real).  FORTRAN real is compiled as  C float and FORTRAN double as C double, so doubles have to be 8-bytes long for equivalence and common statements to be properly aligned.  There are a few other cases where the size of double variables matters; see AT&T Computing Science Technical Report  No. 149 (included with Mac F2C) for a detailed discussion.
  157.         
  158. IF you compile your program with the option Local variables are automatic and you do not have large static data structures, you might not need Far Data.  You need to verify this on a case-by-case basis.
  159.         
  160. Mac F2C creates large static data structures for I/O.  If you create local variables in the global area (static instead of automatic) or  if you have other static data, you will almost certainly require Far Data.  The I/O data structures can be large enough that you may  require Far Data for that reason alone.  
  161.  
  162. The 68K project files are all set to use the Smart code model. That means, the compiler generates a combination of the far and near (32 bit and 16 bit) addressing types, using near when possible. Segments are not limited to 32K of object code.
  163.         
  164. I suggest to stick with this option, since the Large code model doesn‚Äôt usually give you advantages over Smart, and Small requires a jump table for inter-segment jumps which has a negative effect on code size and speed. But you can try and put all files into one segment if your program is small enough and doesn‚Äôt use much of the library code.  You need to verify this on a case-by-case basis.  If you are working with very large FORTRAN programs, you may get a link error from Codewarrior saying something to the effect that 16-bit offsets aren‚Äôt enough to reach some function or other.  In this case you can simply select the Large code model to solve the problem.   
  165.         
  166. If you change the 8-byte doubles, Smart, Far Data or 68881 options, remember to also change them in all the Mac F2C libraries, specifically libI77.68K and libF77.68K, and include the appropriate ANSI library.  The standard ANSI library used in the F2C project files is ANSIFa(4i/8d) C.68K.Lib.  The ‚ÄòFa‚Äô stands for ‚ÄúFar Model‚Äù and the arguments inside the parentheses show the compiler options (4-byte integers/8-byte doubles).  For example, if you don‚Äôt need 8-byte doubles, use ANSIFa(4i) C.68K.Lib, if you want direct 68881 support, use ANSIFa(4i/F/8d) C.68K.Lib.
  167.  
  168. I urge all users to read the enclosed AT&T Computing Science Technical Report No. 149.  Consider it your compiler and language reference manual.  You can print the report by downloading it to any PostScript printer.  You can use Apple‚Äôs LaserWriter Utility application to do this or you can use any of the many equivalent utilities.